﻿
using System;
using System.Web.Mvc;
using Crawler.Job;
using Crawler.Stuff;
using Quartz;


namespace WebUI.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        private static IScheduler sched;

        public ActionResult Index()
        {
            ViewData["IsStarted"] = ParserJobListener.IsRunning;
            return View();
        }

        public ActionResult ScheduleJob()
        {
            sched = Scheduler.Schedule();
            return RedirectToAction("Index", "Home");
        }

        public ActionResult ExecuteJob()
        {
            sched = Scheduler.ScheduleForOneTime();
            return RedirectToAction("Index", "Home");
        }

        public ActionResult InterruptScheduledJob()
        {
            sched.Interrupt("ParserJob", null);
            sched.DeleteJob("ParserJob", null);
            return RedirectToAction("Index", "Home");
        }

        public ActionResult InterruptExecutedJob()
        {
            sched.DeleteJob("ParserJobOneTime", null);
            sched.Interrupt("ParserJobOneTime", null);
            return RedirectToAction("Index", "Home");
        }

        public ActionResult UpdateGrowth(int day, int month)
        {
            sched = Scheduler.ScheduleGrowthForOneTime(day, month);
            return RedirectToAction("Index", "Home");
        }

        public ActionResult InterruptUpdateGrowth()
        {
            sched.DeleteJob("GrowthJobOneTime", null);
            sched.Interrupt("GrowthJobOneTime", null);
            return RedirectToAction("Index", "Home");
        }
    }
}
